<template>
  <el-row :gutter="20" class="overview-row">
    <el-col :span="6" v-for="(item, index) in overviewStats" :key="index">
      <el-card class="overview-card" @click="handleCardClick(item)">
        <div class="overview-content">
          <div class="overview-icon" :style="{ backgroundColor: item.color }">
            <el-icon :size="24">
              <component :is="getIcon(item.icon)" />
            </el-icon>
          </div>
          <div class="overview-info">
            <div class="overview-title">{{ item.name }}</div>
            <div class="overview-number">{{ item.value }}</div>
            <div class="overview-trend" v-if="item.trend">
              <el-icon :size="12" :class="getTrendClass(item.trend.type)">
                <component
                  :is="
                    item.trend.type === 'up'
                      ? ArrowUp
                      : item.trend.type === 'down'
                        ? ArrowDown
                        : Minus
                  "
                />
              </el-icon>
              <span>{{ item.trend.value }}%</span>
            </div>
          </div>
        </div>
      </el-card>
    </el-col>
  </el-row>
</template>

<script setup lang="ts">
  import * as ElementPlusIconsVue from '@element-plus/icons-vue'
  import { ArrowUp, ArrowDown, Minus } from '@element-plus/icons-vue'

  interface OverviewItem {
    name: string
    value: number
    icon: string
    color: string
    trend?: {
      type: 'up' | 'down' | 'stable'
      value: number
    }
  }

  interface Props {
    overviewStats: OverviewItem[]
    onCardClick: (item: OverviewItem) => void
  }

  const props = defineProps<Props>()

  // 获取图标组件
  const getIcon = (iconName: string) => {
    // Element Plus 图标名称映射
    const iconMap: Record<string, any> = {
      'pay-circle': ElementPlusIconsVue.CircleCheck,
      'file-done': ElementPlusIconsVue.DocumentChecked,
      'file-add': ElementPlusIconsVue.DocumentAdd,
      user: ElementPlusIconsVue.User,
      'file-text': ElementPlusIconsVue.Document,
      'shopping-cart': ElementPlusIconsVue.ShoppingBag,
      'check-circle': ElementPlusIconsVue.CircleCheck,
      scale: ElementPlusIconsVue.HomeFilled, // 临时替代
      'user-add': ElementPlusIconsVue.User, // 临时替代
      calendar: ElementPlusIconsVue.Calendar,
      edit: ElementPlusIconsVue.Edit,
      document: ElementPlusIconsVue.Document,
    }
    return iconMap[iconName] || ElementPlusIconsVue.User
  }

  // 获取趋势样式类
  const getTrendClass = (trendType: string) => {
    return trendType === 'up' ? 'trend-up' : trendType === 'down' ? 'trend-down' : 'trend-stable'
  }

  // 处理卡片点击
  const handleCardClick = (item: OverviewItem) => {
    props.onCardClick(item)
  }
</script>

<style scoped lang="scss">
  .overview-row {
    margin-bottom: 20px;
  }

  .overview-card {
    cursor: pointer;
    transition: all 0.3s ease;
    &:hover {
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
  }

  .overview-content {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .overview-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
  }

  .overview-info {
    flex: 1;
  }

  .overview-title {
    font-size: 14px;
    color: #909399;
    margin-bottom: 8px;
  }

  .overview-number {
    font-size: 24px;
    font-weight: bold;
    color: #303133;
    margin-bottom: 4px;
  }

  .overview-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
  }

  .trend-up {
    color: #f56c6c;
  }

  .trend-down {
    color: #67c23a;
  }

  .trend-stable {
    color: #909399;
  }
</style>
